package com.bookshop.util;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author g2l
 * @create 2023-12-25 18:36
 */
public class OrderUtil {
    private static final AtomicInteger id = new AtomicInteger(1000);
    public static String getNo() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssS");
        String prefix = sdf.format(new Date()) + getId();
        String result = UUID.randomUUID().toString().replace("-","").substring(0,5);
        return prefix + result;
    }
    // 返回一个1000-9999的数
    private static String getId(){
        return String.valueOf(id.get() >= 9999 ? id.getAndIncrement() : id.getAndSet(1000));
    }

}
